use wd_run::{Input, TaskInfo};

#[derive(Debug,Clone,Eq, PartialEq)]
pub struct Info{
    version : String,
    time: String,
    author: String,
    format: String,
}
impl Default for Info{
    fn default() -> Self {
        Self{
            version:"0.1.0".into(),
            time:"2022-01-02 23:12:15".into(),
            author: "teshin".into(),
            format: String::new(),
        }
    }
}

#[wd_run::async_trait]
impl wd_run::Task for Info {
    fn info(&self) -> TaskInfo {
        TaskInfo::new("info","show application info")
            .register_arg("--format","version:{version} \ntime:{time} \nauthor:{author}","info input format")
    }

    async fn run(&self,mut input:Input) -> wd_run::Result<()> {
        let info = input.load::<String>("format").unwrap();

        let info = info.replace("{version}", self.version.as_str());
        let info = info.replace("{time}", self.time.as_str());
        let info = info.replace("{author}", self.author.as_str());

        println!("-----------------> application info <------------------");
        println!("{}",info);
        Ok(())
    }

    async fn exit(&self,_input:Input) -> wd_run::Result<()> {
        println!("-----------------> over <------------------");
        Ok(())
    }
}